<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>04-文字</title>
  <style>
    body {
      background-color: #000;
      text-align: center;
    }
    #c1 {
      background-color: #fff;
    }
  </style>
</head>
<body>
  <canvas id="c1" width="800" height="600"></canvas>

  <script>
    window.onload = function() {
      const oC = document.getElementById('c1')
      const gd = oC.getContext('2d')

      const startX = 100
      const startY = 100

      gd.beginPath()
      // font样式设置与css相同
      gd.font = '50px sans-serif'

      // 文字填充颜色
      gd.fillStyle = 'red'
      gd.fillText('hello world', startX, startY)

      // 文字边框颜色
      gd.font = '20px serif'
      gd.strokeStyle  = 'green'
      gd.strokeText('hello world', 200, 200)
    }
  </script>
</body>
</html>